<template>
  <div class="map_content">
    <div class="map_">
      <baidu-map class="map" style="height:7.7rem" @ready="map_handler" :center="{ lng: 117.075865, lat: 36.66031 }" :mapStyle="mapStyle" :zoom="zoom" :scroll-wheel-zoom="true">
              <bm-marker v-for="(item,index) in markes" :position="item.position" :dragging="false"  @click="marker_event(index)" :key="index" :icon="{url: 'http://118.190.37.219:9000/shopping/dw.png', size: {width: 35, height: 35}}">
                <bm-label :offset="{width: -15, height: 10}" :content="item.content" :labelStyle="labelStyle" />
              </bm-marker>
              <bm-polygon v-for="(items,index) in polygons" :key="index" :path="items.path" stokeColor:='#09C8C6' :fillColor="items.fillColer" stroke-opacity=0.2 :strokeOpacity=1 :strokeWeight=1.3 :editing="true"></bm-polygon>
            </baidu-map>
      <transition name="bounce">
        <div class="bt flex_a" v-if="show">
          <img class="back" src="../assets/up_.png" alt="" @click="shows">
          <div class="bt_content">
            <div class="map_top">
              <img src="../assets/dj.png" alt="">
              <span>党建工作站分布</span>
            </div>
            <div class="map_bottom">
              <img src="../assets/rlfx.png" alt="">
              <span>热力分析</span>
            </div>
          </div>
          <div class="bt_content">
            <div class="map_top">
              <img src="../assets/sphj.png" alt="">
              <span>网格力量多人视频呼叫</span>
            </div>
            <div class="map_bottom">
              <img src="../assets/csbj.png" alt="">
              <span>城市部件</span>
            </div>
          </div>
          <div class="bt_content">
            <div class="map_top">
              <img src="../assets/wgy.png" alt="">
              <el-dropdown placement="top">
                <span class="el-dropdown-link">
                  <span>网格员分布</span>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>重点服务人员分布</el-dropdown-item>
                  <el-dropdown-item>重点管理人员分布</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <img class="up" src="../assets/up_.png" alt="">
            </div>
            <div class="map_bottom">
              <img src="../assets/wgll.png" alt="">
              <el-dropdown placement="top">
                <span class="el-dropdown-link">
                  <span>网格力量分布</span>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>重点服务人员分布</el-dropdown-item>
                  <el-dropdown-item>重点管理人员分布</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <img class="up" src="../assets/up_.png" alt="">
            </div>
          </div>
          <div class="bt_content">
            <div class="map_top">
              <img src="../assets/zdglry.png" alt="">
              <el-dropdown placement="top">
                <span class="el-dropdown-link">
                  <span>重点管理人员分布</span>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>重点服务人员分布</el-dropdown-item>
                  <el-dropdown-item>重点管理人员分布</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <img class="up" src="../assets/up_.png" alt="">
            </div>
            <div class="map_bottom">
              <img src="../assets/zdfury.png" alt="">
              <el-dropdown placement="top">
                <span class="el-dropdown-link">
                  <span>重点服务人员分布</span>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>重点服务人员分布</el-dropdown-item>
                  <el-dropdown-item>重点管理人员分布</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <img class="up" src="../assets/up_.png" alt="">
            </div>
          </div>
        </div>
      </transition>
      <div class="down" v-if="hide">
        <img src="../assets/64--27.png" alt="">
        <img src="../assets/up_.png" class="xiangshang" alt="" @click="hides">
      </div>
    </div>
    <div class="tableData">
      <div class="table_title flex_b">
        <span>标题</span>
        <span>状态</span>
        <span>类型</span>
        <span>事件来源</span>
        <span>地点</span>
        <span>网格</span>
        <span>发生时间</span>
      </div>
      <vue-seamless-scroll :data="list" :class-option="classOption" class="table-content">
        <div class="table_title_text flex_b" v-for="(item,index) in list" :key="index">
          <span @click="titleDetails" class="point">{{item.eventTatil}}</span>
          <span>{{item.eventStatic}}</span>
          <span>{{item.eventType}}</span>
          <span>{{item.eventGrid}}</span>
          <span>{{item.eventPlace}}</span>
          <span>{{item.eventGrid}}</span>
          <span>{{item.eventDate}}</span>
        </div>
      </vue-seamless-scroll>
    </div>
    <event-details :isShow="dialogFormVisible1" @close1="closeDialog1"></event-details>
  </div>
</template>

<script>
// import BMap from 'BMap'
import Vue from "vue";
import BaiduMap from "vue-baidu-map";
Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: "1CHci8ORyfONSm6I84NZhyD9ksGRV8jF&s=1"
});
import eventDetails from '@/components/eventDetails';
import {ScrollEvent,getGrid } from '@/api/index';
// import { AMapManager } from 'vue-amap';

export default {
  components: {
    eventDetails,
  },
  data() {
    return {
       markes: [],
        upgridCode: "",
            mapStyle: {
        styleJson: [
          {
            featureType: "background",
            elementType: "all",
            stylers: {
              color: "#1d2125ff"
            }
          },
          {
            featureType: "water",
            elementType: "all",
            stylers: {
              color: "#3d85c6ff"
            }
          },
          {
            featureType: "local",
            elementType: "all",
            stylers: {
              color: "#0c1721ff"
            }
          },
          {
            featureType: "arterial",
            elementType: "all",
            stylers: {
              color: "#7a8895ff"
            }
          },
          {
            featureType: "poilabel",
            elementType: "labels.text.fill",
            stylers: {
              color: "#00a7d2ff"
            }
          },
          {
            featureType: "poilabel",
            elementType: "labels.text.stroke",
            stylers: {
              color: "#110c04ff"
            }
          }
        ]
      },
      code: 370102012,
      zoom: 13,
      center: [117.031835, 36.678417],
      dialogFormVisible1: false,
      list: [
        {
          title: '公示牌杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示牌杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示牌杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示牌杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示牌杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示牌杂乱阿萨德',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示牌杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示牌杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示牌杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示牌杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示ha杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
        {
          title: '公示牌杂乱',
          status: '已处理',
          type: '城市管理事件',
          laiyuan: '文东街道',
          address: '文东街道',
          gird: '第一网格',
          time: '2020-06-29 15:12:00',
        },
      ],
       polygons: [],
      show: true,
      hide: false,
      classOption: {
        singleHeight: 57,
        step: 0.5,
        hoverStop: true,
      },
      // 地图
      eventNumberCount: {},
      getEventRankListArr: [],
      map: "",
      Bmap: "",
      loading1: true,
      eventNumberList: [],
      chuzhiLoading: true,
      event_pie_loading: true,
     
      labelStyle: {
        color: "#fff",
        fontSize: "14px",
        border: "none",
        background: "transparent"
      },
      
    };
  },
  computed: {},
  created(){
this.ScrollEvents()
this.getGrids()
  },
  mounted() {
    // this.getMapBasicInfo();
    
  },

  methods: {
     marker_event(index) {
      this.zoom = 17;
      let id = this.markes[index].gridCode;
      this.getGrids(id);
  },
    async ScrollEvents(){
       try {
        const{data}  = await ScrollEvent()
        // console.log(data)
         this.list=data.date
      } catch (error) {
        console.log(error)
      }
    },
    drawLine(e) {
      console.log(e);
      let treeLevel = e.target.Uh.extData.treeLevel;
      if (treeLevel == 1) {
        this.getMapBasicInfo1(e.target.Uh.extData.streetCode);
      }
      if (treeLevel == 2) {
        this.getMapBasicInfo1(e.target.Uh.extData.communityCode);
      }
      if (treeLevel == 3) {
        this.getMapBasicInfo1(e.target.Uh.extData.gridBasicId);
      }
    },
    

    setArrar(arr) {
      const newArr = [];
      var wendongStr = arr
        .split(';')
        .toString()
        .split(',');
      let len = wendongStr.length;
      let n = 2;
      let lineNum = len % 2 === 0 ? len / 2 : Math.floor(len / 2 + 1);
      for (let i = 0; i < lineNum; i++) {
        let temp = wendongStr.slice(i * n, i * n + n);
        newArr.push(temp);
      }
      return newArr;
    },
    closeDialog1() {
      this.dialogFormVisible1 = false;
    },
    titleDetails() {
      console.log(1);
      this.dialogFormVisible1 = true;
    },
    
    GaodeMap() {},
    // 地图
    //  初始化地图调用api
    map_handler({ BMap, map }) {
      // let _this = this;
      this.BMap = BMap;
      this.map = map;
    },
    shows() {
      this.show = false;
      this.hide = true;
    },
    hides() {
      this.show = true;
      this.hide = false;
    },
    returnUp() {
      this.getGrids(this.upgridCode);
    },
  //获取网格社区
    getGrids(id) {
      // let self = this;
      let markes = this.markes;
      let polygons = this.polygons;

      getGrid({gridCode:id}).then(res => {
        if (res.data.result == true) {
          let arr = res.data.date.gps;
          arr.forEach(element => {
            polygons.push({
              path: element.polygonPaths,
              fillColer: element.fillColer
            });
            markes.push({
              position: element.centrePoint,
              content: element.gridName,
              gridCode: element.gridCode
            });
          });
          this.map.centerAndZoom(res.data.date.centre, 15);
          this.upgridCode = res.data.date.upGridCode;
        }
      });
  }
    },
  //    marker_event(index) {
  //     this.zoom = 17;
  //     let id = this.markes[index].gridCode;
  //     this.getGrid(id);
  // },
};
</script>

<style lang="scss">
.map_content {
  .map_ {
    height: 7.8rem;
    position: relative;
    .map {
      height: 7.8rem;
      width: 100%;
    }
    .down {
      position: absolute;
      bottom: -1%;
      z-index: 1000;
      img {
        width: 100%;
        height: 0.2rem;
      }
      .xiangshang {
        width: 0.2rem;
        height: 0.2rem;
        position: absolute;
        left: 49%;
        top: 0;
      }
    }
    .bt {
      bottom: 11%;
      z-index: 1000;
      position: absolute;
      height: 0.9rem;
      width: 100%;
      background-image: url('../assets/djbg.png');
      background-size: 100% 100%;
      background-position: center center;
      margin-bottom: 0.1rem;
      position: relative;
      .back {
        position: absolute;
        transform: rotate(180deg);
        -webkit-transform: rotate(180deg);
        left: 49%;
        margin-right: -0.2rem;
        top: 0;
        width: 0.2rem;
        height: 0.2rem;
      }
      .bt_content {
        .map_top {
          height: 0.4rem;
          width: 1.99rem;
          display: flex;
          align-items: center;
          justify-content: center;
          background: linear-gradient(to bottom, #2f88dd 0%, #02135b 30%, #2f88dd 100%);
          border-radius: 1rem 1rem 0 0;
          img {
            width: 0.2rem;
            height: 0.2rem;
          }
          span {
            color: #fff;
            font-size: 0.1rem;
            padding-left: 0.01rem;
          }
          .up {
            width: 0.2rem;
            height: 0.2rem;
            padding-left: 0.1rem;
          }
        }
        .map_bottom {
          height: 0.4rem;
          width: 1.99rem;
          margin-top: 0.03rem;
          display: flex;
          align-items: center;
          justify-content: center;
          background: linear-gradient(to bottom, #2f88dd 0%, #02135b 30%, #2f88dd 100%);
          border-radius: 0 0 1rem 1rem;
          .up {
            width: 0.2rem;
            height: 0.2rem;
            padding-left: 0.1rem;
          }
          img {
            width: 0.2rem;
            height: 0.2rem;
          }
          span {
            color: #fff;
            font-size: 0.1rem;
            padding-left: 0.01rem;
          }
        }
      }
    }
  }
  .BMap_vectex{
    height: 0 !important;
  }
  .tableData {
    height: 4.8rem;
    width: 100%;
    background: #030244;
    overflow: hidden;
    .table_title {
      position: relative;
      z-index: 1000;
      text-align: center;
      line-height: 0.4rem;
      span {
        width: 1.15rem;
        color: #fff;
        height: 0.4rem;
        font-size: 0.18rem;
        background: linear-gradient(to bottom, #2f88dd 0%, #2f88dd 20%, #082c77 50%, #2f88dd 100%);
      }
    }
    .table_title_text {
      text-align: center;
      line-height: 0.4rem;
      width: 100%;
      border-top: 1px solid #060682;
      border-bottom: 1px solid #060682;
      span {
        color: #fff;
        width: 1.15rem;
        height: 0.4rem;
        font-size: 0.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }
}
.el-dropdown-menu {
  background: linear-gradient(to bottom, #2f88dd 0%, #02135b 30%, #2f88dd 100%) !important;
  opacity: 0.8;
  .el-dropdown-menu__item {
    color: #55c5d9;
    font-size: 0.2rem;
  }
}
.bounce-enter-active {
  animation: bounce-in 0.5s;
}
.bounce-leave-active {
  animation: bounce-in 0.5s reverse;
}
@keyframes bounce-in {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1);
  }
}
.amap-marker-content {
  position: relative;
  color: #11adea !important;
  font-size: 0.24rem;
  font-weight: 800;
}
.amap-controls {
  .amap-maptypecontrol {
    position: absolute;
    top: 73%;
    right: 0;
    z-index: 304;
  }
  .amap-maptype-con {
    position: absolute;
    top: 0;
    right: 0;
    width: 60px;
    height: 60px;
    background: transparent;
    border: none;
    cursor: pointer;
    .amap-maptype-win {
      position: absolute;
      top: 1px;
      right: 1px;
      width: 56px;
      height: 56px;
      overflow: hidden;
      background: #ccc;
      border: none;
      display: none;
    }
  }
  .amap-maptype-title {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 60px;
    height: 20px;
    color: #55c5d9;
    text-align: center;
    font-size: 0.16rem;
    line-height: 20px;
    background: #03123d;
  }
  .amap-maptype-list {
    border: none;
  }
  .amap-maptype-check {
    display: inline-block;
    width: 15px;
    height: 15px;
    margin-left: -2px;
    background: url(https://webapi.amap.com/theme/v1.3/maptype-bg.png) no-repeat -30px 4px;
  }
  .amap-maptype-list p {
    width: 100px;
    height: 20px;
    color: #55c5d9;
    margin: 0;
    cursor: pointer;
    background: #03123d;
    .amap-maptype-label {
      display: inline-block;
      width: 60px;
      height: 15px;
      color: #55c5d9;
      font-size: 0.16rem;
      line-height: 15px;
      margin-left: 10px;
    }
  }
}
</style>

